package com.qishon.pc.domain.service;

import com.qishon.pc.domain.model.MasPartHd;
import com.qishon.pc.domain.repository.PreViewRepository;
import com.qishon.pc.domain.repository.impl.PreViewRepositoryImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by yuquan.hu on 2016/12/23.
 */
@Service
@Slf4j
public class PreViewService {
    //获取渲染文件路径
    @Value("${run.path}")
    private String filePath;

    //获取图片分辨率
    @Value("${image.Types}")
    private String imageTypes;

    //获取图片分辨率对应尺寸
    @Value("${image.Types.heights}")
    private String imageTypesHeights;

    @Autowired
    PreViewRepositoryImpl preViewRepositoryImpl;

    public MasPartHd findMasPartByPartCode(Map<String, Object> params){
        log.info("MasPartHd findMasPartByPartCode: " + filePath);
        MasPartHd tempMasPartHd = preViewRepositoryImpl.findMasPartByPartCode(params);

        String[] imageTypesArray = imageTypes.split(",");
        String[] imageTypesHeightsArray = imageTypesHeights.split(",");
        for (int i=0;i<imageTypesArray.length;i++) {
            if(imageTypesArray[i].equals(params.get("imageType").toString()))
            {
                tempMasPartHd.setImageSize(imageTypesHeightsArray[i]);
                break;
            }
        }
        //return preViewRepositoryImpl.findMasPartByPartCode(params);
        return tempMasPartHd;
    }

}
